package com.yunsom.testdemo.design.chain_of_responsibility;

import java.util.Objects;

/**
 * @author Xbao
 * @description
 * @date 2022/6/22 11:21
 */
public abstract class AbstractLogger {

  public static int INFO = 1;
  public static int DEBUG = 2;
  public static int ERROR = 3;

  protected int level;

  protected AbstractLogger nextLogger;

  public void setNextLogger(AbstractLogger nextLogger){
    this.nextLogger = nextLogger;
  }

  public void logMessage(int level, String message){
    if(this.level <= level){
      write(message);
    }
    if(Objects.nonNull(nextLogger)){
      nextLogger.logMessage(level, message);
    }
  }

  abstract protected void write(String message);

}
